<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">

            <div class="layui-card-body cardbody">
              <div class="layui-form" lay-filter="">

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">安卓上传</label>
                    <div class="layui-input-inline">
                      <button type="button" class="layui-btn" id="test1">上传安卓地址</button>
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">安卓地址</label>
                    <div class="layui-input-inline">
                      <input type="text" name="androidAddress" placeholder="请输入地址" autocomplete="off"
                        class="layui-input" v-model="itemData.androidAddress">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">安卓版本号</label>
                    <div class="layui-input-inline">
                      <input type="text" name="androidVersion" placeholder="请输入版本号" autocomplete="off"
                        class="layui-input" v-model="itemData.androidVersion">
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div style="height:10px;background:rgb(242, 242, 242);"></div>

            <div class="layui-card-body cardbody">
              <div class="layui-form" lay-filter="">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">苹果上传</label>
                    <div class="layui-input-inline">
                      <button type="button" class="layui-btn" id="test2">上传苹果地址</button>
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">苹果地址</label>
                    <div class="layui-input-inline">
                      <input type="text" name="appleAddress" placeholder="请输入地址" autocomplete="off" class="layui-input"
                        v-model="itemData.appleAddress">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">苹果版本号</label>
                    <div class="layui-input-inline">
                      <input type="text" name="appleVersion" placeholder="请输入版本号" autocomplete="off" class="layui-input"
                        v-model="itemData.appleVersion">
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div style="height:10px;background:rgb(242, 242, 242);"></div>

            <div class="layui-card-body cardbody">
              <div class="layui-form" lay-filter="">
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">源码上传</label>
                    <div class="layui-input-inline">
                      <button type="button" class="layui-btn" id="test3">上传小程序源码地址</button>
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">小程序源码地址</label>
                    <div class="layui-input-inline">
                      <input type="text" name="appletPackageAddress" placeholder="请输入地址" autocomplete="off"
                        class="layui-input" v-model="itemData.appletPackageAddress">
                    </div>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">审核状态</label>
                  <div class="layui-input-inline">
                    <select name="auditStatus" lay-filter="auditStatus" v-model="itemData.auditStatus">
                      <option value="UNAUDITED">待审核</option>
                      <option value="AUDIT_PASS">审核通过</option>
                      <option value="AUDIT_FAILED">审核不通过</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item layui-form-text">
                  <label class="layui-form-label">备注</label>
                  <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" v-model="itemData.remarks"></textarea>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn  layui-btn-normal" @click="sure">确定</button>
                  </div>
                </div>

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'usersetem',
  data () {
    return {
      id: "",
      itemData: {
        androidAddress: '',// 安卓地址
        androidVersion: '',//安卓版本号
        appleAddress: '',// 苹果地址
        appleVersion: '',//苹果版本号
        appletPackageAddress: '', //小程序APP安装包地址
        auditStatus: '', //审核状态
        remarks: '', //备注

      }
    }
  },
  mounted () {
    var vm = this;
    window.getdates = this.getdates;
    layui.use('upload', function () {
      var $ = layui.jquery
        , upload = layui.upload;
      upload.render({
        elem: '#test1',
        data: {
          type: 3
        }
        , url: 'http://storage.g2ma.com/imgUpload/installationPackage' //上传接口
        , accept: 'file'
        , done: function (res) {
          layer.msg('上传成功');
          vm.itemData.androidAddress = res.msg;
        }
        , error: function () {
          layer.msg('上传失败');
        }
      });
      upload.render({
        elem: '#test2'
        , data: {
          type: 3
        }
        , url: 'http://storage.g2ma.com/imgUpload/installationPackage' //上传接口
        , accept: 'file'
        , done: function (res) {
          layer.msg('上传成功');
          vm.itemData.appleAddress = res.msg;
        }
        , error: function () {
          layer.msg('上传失败');
        }
      });
      upload.render({
        elem: '#test3'
        , data: {
          type: 3
        }
        , url: 'http://storage.g2ma.com/imgUpload/installationPackage' //上传接口
        , accept: 'file'
        , done: function (res) {
          layer.msg('上传成功');
          vm.itemData.appletPackageAddress = res.msg;
        }
        , error: function () {
          layer.msg('上传失败');
        }
      });
    })
  },
  methods: {
    getdates: function (data) {
      var vm = this;
      this.id = data.id;
      var url = "/advert/aapi/v1.9/apply-setting/" + data.id;
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        vm.itemData = ret.data;
      });
    },
    sure: function () {
      var vm = this;

      // var tid = 'POST';
      var dates = this.itemData;
      // if (this.id) {
      //   dates.id = this.id;
      //   tid = 'PUT';
      // }
      var url = "/advert/aapi/v1.9/apply-setting";
      ajaxRequest(url, "POST", "json", dates, function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
          parent.location.reload();
        }, 1000);
      })
    }
  },
  updated: function () {
    var vm = this;
    layui.use('form', function () {
      var form = layui.form;
      form.render();
      form.on("select(auditStatus)", function (data) {
        vm.itemData.auditStatus = data.value;
      });
    });

  },
}
</script>
<style scoped>
.layui-form-label {
  width: 120px;
  font-size: 15px;
}
</style>